package org.come.control;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Map.Entry;

import com.tool.role.RoleData;
import com.tool.tcp.SpriteFactory;
import org.come.Frame.AchievemJframe;
import org.come.Frame.AchievemMinJframe;
import org.come.action.FromServerAction;
import org.come.model.Achievement;
import org.come.until.DataUtil;
import org.come.until.FormsManagement;
import org.come.until.UserMessUntil;

import org.come.until.Util;

/**
 * 功绩千秋
 * @author Administrator
 *
 */
public class AchievemControl implements FromServerAction {
    @Override
    public void controlMessFromServer(String mes,String type) {
//        System.out.println("mes:" + mes);
        //打开获取
        if (mes.contains("功绩千秋")) {
        	List<Achievement> mapList = new ArrayList<>();
            Set<Entry<Integer, Achievement>> entrySet = UserMessUntil.getAllAchievement().getAllAchievement().entrySet();
            for (Entry<Integer, Achievement> entry : entrySet) {
            	Achievement ach = entry.getValue();
            	if(ach.getConditions().equals(mes.split("=")[1])) {
            		FormsManagement.showForm(3073);
            		if(DataUtil.isNotEmpty(AchievemJframe.getAchievemJpanel())) {
            			AchievemJframe.getAchievemJpanel().setSelectCompleteAchievement(); // 设置已完成的成就节点
            		}
            		AchievemMinJframe.getAchievemMinJpanel().getMcbel().setText(ach.getConditions());
            		AchievemMinJframe.getAchievemMinJpanel().getGjbel().setText(ach.getPrice());
            		AchievemMinJframe.getAchievemMinJpanel().getMsgbel().setText(ach.getDescribeText());
					AchievemMinJframe.getAchievemMinJpanel().setTriple(SpriteFactory.VloadSprite("resource/mouse/BJF ("+ Util.random.nextInt(41)+").tcp", null));
            		AchievemMinJframe.getAchievemMinJpanel().x = 345/2;
            		AchievemMinJframe.getAchievemMinJpanel().w = 1;
            		Thread thread = new Thread(new Runnable() {
                        @Override
                        public void run() {
                        	try {
                        		while (AchievemMinJframe.getAchievemMinJpanel().x>0) {
									AchievemMinJframe.getAchievemMinJpanel().x = AchievemMinJframe.getAchievemMinJpanel().x - 1;
									AchievemMinJframe.getAchievemMinJpanel().w = AchievemMinJframe.getAchievemMinJpanel().w + 2;
									Thread.sleep(1);
								}
								if(AchievemMinJframe.getAchievemMinJpanel().x<=0){
									Thread.sleep(3000);
									FormsManagement.HideForm(3073);
								}
            				} catch (Exception e) {
            					// TODO Auto-generated catch block
            					e.printStackTrace();
            				}
                        }
                    });
                    thread.start();
            	}
            }
        }
    }
}
